export default {

    namespace: 'example',

    state: {
        mapLines: [{
            id: 'line0',
            paths: [[75.757904,38.118117],[117.375719,24.598057],[115.375719,28.598057]],
        },{
            id: 'line1',
            paths: [[76.757904,38.118117],[119.375719,24.598057],[114.375719,28.598057]],
        }],
        mapPoints: [{
            id:'p00',
            longitude:116.468021,
            latitude:39.890092,
            markerContent: '<div style="background:#fff;">1111<div>',
            config: {
                markerContentX: -16,
                markerContentY: -9,
                isAnimation: true,
                animationDelay: 10,
                // BAnimationType: 0
            },
            other: 'xxxx'
        },{
            id:'p01',
            longitude:117.468021,
            latitude:39.890092,
            canShowLabel: true,
            config: {
                labelContent: 'asdfasdfasdfasfdasf',
                markerContentX: -13,
                markerContentY: -42,
                isAnimation: true,
                animationDelay: 30,
                // BAnimationType: 1
            }
        }],
        mapPolygons: [{
            id: 'g00',
            rings: [[118.757904,38.118117],[112.375719,24.598057],[115.375719,28.598057]]
        },{
            id: 'g01',
            rings: [[116.757904,36.118117],[115.375719,25.598057],[114.375719,38.598057]]
        }],
        mapCircles: [{
            id: 'c00',
            longitude: 111.98098,
            latitude: 38.0873234,
            radius: 30000
        },{
            id: 'c01',
            longitude: 119.98098,
            latitude: 32.0873234,
            radius: 100000
        }],
        isOpenTrafficInfo: false,
        setVisiblePoints: false,
        mapVisiblePoints: '',
        setCenter: false,
        mapCenter: '',
        setZoomLevel: false,
        mapZoomLevel: '',
        mapCluster: '',
        setCluster: false,
        boundaryName: ['苏州'],
        isRangingTool: false,
        mapDraw: '',
        isDraw: false,
        isCloseDraw: false,
        isClearAll: false,
        mapRemove: [],
        isRemove: false,
        editGraphicId: '',
        isDoEdit: false,
        isEndEdit: false,
        drawLinePoints: {}
    },
    subscriptions: {
        setup({ dispatch, history }) {
        },
    },

    effects: {
        *drawPolyline({payload},{select,put,call}){
            let {drawLinePoints} = yield select(({example})=>example);
            let mapDraw = {
                geometryType: 'polyline',
                parameter: {
                    color: '#ff000f',
                    pellucidity: 0.3,
                    lineWidth: 8
                },
                data: {id: 'polyline-test'}
            };
            yield put({
                type: 'updateState',
                payload: {
                    mapDraw,
                    isDraw: true,
                    drawLinePoints: {
                        ...drawLinePoints,
                        [mapDraw.data.id]: []
                    }
                }
            });
            yield call(delay,1);
            yield put({
                type: 'updateState',
                payload: {
                    isDraw: false
                }
            })
        },
        *clearAll({payload},{select,put,call}){
            yield put({
                type: 'updateState',
                payload: {
                    isClearAll: true,
                    mapPoints: [],
                    mapLines: [],
                    mapPolygons: [],
                    mapCircles: [],
                    boundaryName: [],
                    drawLinePoints: {}
                }
            });
            yield call(delay,1);
            yield put({
                type: 'updateState',
                payload: {
                    isClearAll: false
                }
            })
        },
        *removeGraphic({payload},{select,put,call}){
            let {drawLinePoints} = yield select(({example})=>example);
            let mapRemove = [{
                id: 'polyline-test',
                type: 'draw'      
            }];
            let dlps = {
                ...drawLinePoints
            }
            mapRemove.map((item,index)=>{
                dlps[item.id] = [];
            })
            yield put({
                type: 'updateState',
                payload: {
                    mapRemove,
                    isRemove: true,
                    drawLinePoints: dlps
                }
            });
            yield call(delay,1);
            yield put({
                type: 'updateState',
                payload: {
                    isRemove: false
                }
            })
        },
    },
    reducers: {
        updateState(state, action) {
            return { ...state, ...action.payload };
        }
    },
}

function delay(timeout) {
    let promise = new Promise((resolve,reject)=>{
        setTimeout(resolve,timeout);
    });
    return promise;
}
